package com.tsing.wms.controller;


import com.tsing.wms.annotation.PassToken;
import com.tsing.wms.service.IOrderService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.IdsReqVO;
import com.tsing.wms.vo.req.OrderReqVO;
import com.tsing.wms.vo.req.SupplierPageReqVO;
import com.tsing.wms.vo.resp.GoodsListRespVO;
import com.tsing.wms.vo.resp.OrderRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping("/goodsList")
    @ApiOperation(value = "根据供应商id获取货物列表")
    public ResultData<List<GoodsListRespVO>> goodsList(@Validated IdReqVO reqVO) {
        return ResultUtil.success(orderService.goodsList(reqVO));
    }

    @PostMapping("/addOrder")
    @ApiOperation(value = "新增订单")
    public ResultData addOrder(@Validated({AddGroup.class}) @RequestBody OrderReqVO reqVO, HttpServletRequest request) {
        orderService.addOrder(reqVO, request);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteOrder")
    @ApiOperation(value = "删除订单")
    public ResultData deleteOrder(@Validated @RequestBody IdsReqVO reqVO, HttpServletRequest request) {
        orderService.deleteOrder(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getOrder")
    @ApiOperation(value = "查询订单详情")
    public ResultData<OrderRespVO> getOrder(@Validated IdReqVO reqVO) {
        return ResultUtil.success(orderService.getOrder(reqVO));
    }

    @PutMapping("/updateOrder")
    @ApiOperation(value = "修改订单")
    public ResultData updateOrder(@Validated({UpdateGroup.class}) @RequestBody OrderReqVO reqVO, HttpServletRequest request) {
        orderService.updateOrder(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/orderPage")
    @ApiOperation(value = "订单分页")
    public ResultData<PageResultVO<OrderRespVO>> orderPage(@Validated SupplierPageReqVO reqVO, HttpServletRequest request) {
        return ResultUtil.success(orderService.orderPage(reqVO, request));
    }

    @PassToken
    @GetMapping("/exportOrder")
    @ApiOperation(value = "导出订单")
    public void exportOrder(@Validated IdReqVO reqVO, HttpServletRequest request, HttpServletResponse response) {
        orderService.exportOrder(reqVO, request, response);
    }

}
